package GUI;
/**hofit**/
import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ScrollPaneConstants;

import Client.BusinessImplements;
import java.awt.Font;
import java.awt.Color;
import java.awt.SystemColor;
import java.util.ArrayList;

import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

public class Worker_Details extends Abstract_Jpanel {
	private JTable table;
	JButton btnBack;
	private JPanel panel_1;
	/**
	 * Create the panel.
	 */
	
	public Worker_Details() {
		
		JPanel panel = new JPanel();
		panel.setBorder(new LineBorder(SystemColor.activeCaption, 6));
		panel.setBackground(SystemColor.inactiveCaption);
		panel.setBounds(22, 62, 1132, 579);
		
		panel_1 = new JPanel();
		panel_1.setBounds(50, 641, 172, 51);
		panel_1.setLayout(null);
		
		btnBack = new JButton("back");
		btnBack.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnBack.setBounds(28, 11, 104, 31);
		/**
		 * return to the main menu
		 */
		panel_1.add(btnBack);
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Sign_in_panel sip=new Sign_in_panel();
				on_screen_unload();
				BusinessImplements.GetInstance().getMainFrame().setContentPane(sip);
				sip.setSize(getMaximumSize());
				sip.on_screen_load();
			}
		});
		panel.setLayout(null);
		setLayout(null);
		add(panel_1);
		add(panel);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBorder(new LineBorder(SystemColor.control, 6));
		panel_2.setBackground(new Color(220, 220, 220));
		panel_2.setBounds(57, 58, 957, 420);
		panel.add(panel_2);
		panel_2.setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(96, 50, 773, 310);
		panel_2.add(scrollPane);
		scrollPane.setToolTipText("");
		scrollPane.setViewportBorder(new LineBorder(Color.BLACK, 2));
		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		
		table = new JTable();
		table.setFont(new Font("Tahoma", Font.PLAIN, 14));
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
			},
			new String[] {
				"Name", "Last Name", "Worker Id", "Email", "Adress", "Phone"
			}
		) {
			Class[] columnTypes = new Class[] {
				String.class, String.class, Integer.class, String.class, Object.class, Object.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});
		scrollPane.setViewportView(table);
		//label.setIcon(new ImageIcon("pic\\workers.jpg"));
		
		JLabel lblWorkerDeatails = new JLabel("Worker Deatails");
		lblWorkerDeatails.setFont(new Font("MV Boli", Font.BOLD, 30));
		lblWorkerDeatails.setForeground(new Color(25, 25, 112));
		lblWorkerDeatails.setBounds(22, 11, 289, 40);
		add(lblWorkerDeatails);

	}
	@Override
	public void next_screen() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void prev_screen() {
		// TODO Auto-generated method stub
		
	}
	/**
	 * when the screen load call the function on the server that return all the details of the workers
	 */
	@Override
	public void on_screen_load() {
		ArrayList<String> listWorkers=BusinessImplements.GetInstance().getServerProxy().getAllWorkers();
		setData(listWorkers);

			
	}
	@Override
	public void on_screen_unload() {
		// TODO Auto-generated method stub
		
	}
	/**
	 * 
	 * @param workersDetails
	 * take the details of the workers and put the details on the table
	 */
	public void setData(ArrayList<String> workersDetails) {		
		String[] colums=new String[]{"Name", "Last Name", "Worker Id", "Email","Adress", "Phone"};
        Object[][] data=new Object[workersDetails.size()][6];
        for (int i = 0; i < workersDetails.size(); i++) {
        	String[] hist= workersDetails.get(i).split(",");
        	data[i][0]=hist[0];
        	data[i][1]=hist[1];
        	data[i][2]=hist[2];
        	data[i][3]=hist[4];
        	data[i][4]=hist[3];
        	data[i][5]=hist[5];
		}
        table.setModel(new DefaultTableModel(data,colums));
	}
}
